package com.zhu.utils;

import com.zhu.dao.HobbyDao;
import com.zhu.pojo.Hobby;
import com.zhu.pojo.Student;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class HobbyUtils {
    public static void StudentHobby(List<Student> studentList) throws SQLException {
        List<Hobby> hobbyList = new HobbyDao().getHobby();

        for (Student student : studentList) {
            List<Hobby> hobbys  = new ArrayList<>();
            int hid = student.getHid();
            for (Hobby h : hobbyList) {
                Hobby hobby = new Hobby();
                if ((hid & h.getHid())==0){
                    hobby.setIsSelect(0);
                }else {
                    hobby.setIsSelect(1);
                }
                hobby.setHname(h.getHname());
                hobby.setHid(h.getHid());
                hobbys.add(hobby);
            }
            student.setHobbyList(hobbys);
        }

    }
    public static void StudentHobby(Student student) throws SQLException {
        List<Hobby> hobbyList = new HobbyDao().getHobby();
        for (Hobby hobby : hobbyList) {
            if ((student.getHid() & hobby.getHid())==0){
                hobby.setIsSelect(0);
            }else {
                hobby.setIsSelect(1);
            }
        }
        student.setHobbyList(hobbyList);
    }

}
